#import "WebKitDelegateController.h"

@implementation WebKitDelegateController

- (void)webView:(WebView *)sender 
decidePolicyForNavigationAction:(NSDictionary*)actionInformation
                        request:(NSURLRequest *)request
                          frame:(WebFrame *)frame
               decisionListener:(id<WebPolicyDecisionListener>)listener
{
	//int actionKey = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue];
	//NSURL *url = [actionInformation objectForKey:WebActionOriginalURLKey];
	//if (actionKey == WebNavigationTypeOther || [[url absoluteString] rangeOfString:@"pibb.com"].location != NSNotFound) {
		[listener use];
	//} else {
	//	[[NSWorkspace sharedWorkspace] openURL:url];
	//	[listener ignore];
	//}
}

- (void)webView:(WebView *)sender
decidePolicyForNewWindowAction:(NSDictionary*)actionInformation
                       request:(NSURLRequest *)request
                  newFrameName:(NSString *)frameName
              decisionListener:(id<WebPolicyDecisionListener>)listener
{
	int actionKey = [[actionInformation objectForKey:WebActionNavigationTypeKey] intValue];
	if (actionKey == WebNavigationTypeOther) {
		[listener use];
	} else {
		NSURL *url = [actionInformation objectForKey:WebActionOriginalURLKey];
		[[NSWorkspace sharedWorkspace] openURL:url];
		[listener ignore];
	}
}

- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message
{
	NSRunAlertPanel(@"Diet Pibb", message, @"Ok", nil, nil);
}

- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message
{
	int choice = NSRunAlertPanel(@"Diet Pibb", message, @"Ok", @"Cancel", nil);
	if(choice == NSAlertDefaultReturn) {
		return true;
	} else {
		return false;
	}
}

@end
